﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using TestMySqlConnetPoll;
using System.Threading;
using View.Common;
using ReplayDataFile;

namespace View.Replay
{
    //public interface IReplayControlBar
    //{
    //    event ReplayEventHandler ReplayUIEvent;
    //    TimeSegmentList TotalTimeList
    //    {
    //        get;
    //        set;
    //    }
    //    TimeSegmentList CurReplayTimeList
    //    {
    //        get;
    //    }
    //    TimeSegmentList CacheTimeList
    //    {
    //        get;
    //        set;
    //    }
    //    TimeSpan DisMaxTimeLen
    //    {
    //        get;
    //        set;
    //    }
    //    void SetTimePostion(object setter, TimeSpan pos);
    //    void SetPositionInTotalTime(object setter, TimeSpan pos);
    //    void Stop();
    //    void SetReplayParam(ReplaySettingParam param);
    //    void SetReplayInfo(string infoType, object info);
    //}
    public class ControlBarDlg : Form//, IReplayControlBar
    {
        // Fields
        private Button btnAccuratePosition;
        private Button btnClose;
        private Button btnDisplayAnalogDialog;
        private Button btnDisplayKglDialog;
        private Button btnModeSwitch;
        private Button btnNextSecond;
        private Button btnPlay;
        private Button btnPreSecond;
        private Button btnReload;
        private Button btnReplaySetting;
        private Button btnSave;
        private Button btnSpeedDown;
        private Button btnSpeedUp;
        private ComboBox cmbDate;
        private ComboBox cmbHour;
        private ComboBox cmbMinute;
        private ComboBox cmbSecond;
        private ComboBox cmbSpeed;
        private IContainer components = null;
        private System.Windows.Forms.Timer controlSecondPlayTimer;
        private ReplayProgressBar curReplayBar;
        private GroupBox groupBox1;
        private bool isBtnNextSecondPressed = false;
        private bool isBtnPreSecondPressed = false;
        private Label label10;
        private Label label7;
        private Label label8;
        private Label label9;
        private int lastReplayRecCount;
        private Label lbCurReplayBarBeginTime;
        private Label lbCurReplayBarEndTime;
        private Label lbCurTime;
        private SpeedInfo[] speedTable = new SpeedInfo[] { new SpeedInfo(0.25f, "1/4 倍速"), 
            new SpeedInfo(0.5f, "1/2 倍速"), new SpeedInfo(1f, "1 倍速"), 
            new SpeedInfo(2f, "2 倍速"), new SpeedInfo(4f, "4 倍速"), new SpeedInfo(8f, "8 倍速"),
            new SpeedInfo(10f, "10 倍速"), new SpeedInfo(20f, "20 倍速"), new SpeedInfo(60f, "60 倍速") };
        private TextBox tbTip;
        private ReplayProgressBar totalDataBar;
      

        // Events
        //public event ReplayEventHandler ReplayUIEvent;

        // Methods
        public ControlBarDlg()
        {
            //base.CloseFormWhenPressEnter = false;
            this.InitializeComponent();


        }

        private void btnAccuratePosition_Click(object sender, EventArgs e)
        {
            DateTime accuratePosTimeFromCtrl = this.GetAccuratePosTimeFromCtrl();
            if (accuratePosTimeFromCtrl != DateTime.MinValue)
            {
                if ((this.totalDataBar.TimeSegmentList.GetMaxTime() < accuratePosTimeFromCtrl) || (this.totalDataBar.TimeSegmentList.GetMinTime().AddMilliseconds((double)-this.totalDataBar.TimeSegmentList.GetMinTime().Millisecond) > accuratePosTimeFromCtrl))
                {
                    //MessageBoxShow.Show("设定时间超出历史数据时间范围!", "提示", this);
                }
                else
                {
                    List<TimeSpan> list = this.totalDataBar.TimeSegmentList.Time2Positions(accuratePosTimeFromCtrl);
                    if ((list != null) && (list.Count > 0))
                    {
                        TimeSpan sliderPos = list[0];
                        this.totalDataBar.SetSliderPosition(this, sliderPos);
                        this.totalDataBar.Invalidate();
                    }
                }
            }
        }

        private void btnChangeKglDialog_Click(object sender, EventArgs e)
        {
            //this.FireReplayEvent(ReplayEventType.DisplayChangeKglDialog);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            //this.FireReplayEvent(ReplayEventType.Close);
            this.Close();
        }

        private void btnDiagnose_Click(object sender, EventArgs e)
        {
            //this.FireReplayEvent(ReplayEventType.Diagnose);
        }

        /// <summary>
        /// 历史模拟量曲线回放
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDisplayAnalogDialog_Click(object sender, EventArgs e)
        {

            //this.FireReplayEvent(ReplayEventType.DisplayAnalogDialog);
        }

        private void btnDisplayKglDialog_Click(object sender, EventArgs e)
        {
            //this.FireReplayEvent(ReplayEventType.DisplayKglDialog);
        }

        private void btnModeSwitch_Click(object sender, EventArgs e)
        {
            this.SetDisplayMode((this.btnModeSwitch.Text == "精简") ? "精简" : "高级");
        }

        private void btnNextSecond_Click(object sender, EventArgs e)
        {
            //this.FireReplayEvent(ReplayEventType.PlayNextSecond);
        }

        private void btnNextSecond_MouseDown(object sender, MouseEventArgs e)
        {
            this.controlSecondPlayTimer.Start();
            this.isBtnNextSecondPressed = true;
        }

        private void btnNextSecond_MouseUp(object sender, MouseEventArgs e)
        {
            this.controlSecondPlayTimer.Stop();
            this.isBtnNextSecondPressed = false;
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            if (this.btnPlay.Text == "播放")
            {
                MySql.ReadReplayData(this.curReplayBar.TimeSegmentList.GetBeginTime(), 10);
                //this.FireReplayEvent(ReplayEventType.Start);
                this.btnPlay.Text = "停止";
            }
            else
            {
                //this.FireReplayEvent(ReplayEventType.Pause);
                this.btnPlay.Text = "播放";
            }
        }

        private void btnPreSecond_Click(object sender, EventArgs e)
        {
            //this.FireReplayEvent(ReplayEventType.PlayPreSecond);
        }

        private void btnPreSecond_MouseDown(object sender, MouseEventArgs e)
        {
            this.controlSecondPlayTimer.Start();
            this.isBtnPreSecondPressed = true;
        }

        private void btnPreSecond_MouseUp(object sender, MouseEventArgs e)
        {
            this.controlSecondPlayTimer.Stop();
            this.isBtnPreSecondPressed = false;
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            //ReplayEventArgs args = new ReplayEventArgs
            //{
            //    EeventType = ReplayEventType.Reload
            //};
            //this.FireReplayEvent(this, args);
        }

        private void btnReplaySetting_Click(object sender, EventArgs e)
        {
            //this.FireReplayEvent(ReplayEventType.ReplaySetting);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            //this.FireReplayEvent(ReplayEventType.SaveData);
        }

        private void btnSpeedDown_Click(object sender, EventArgs e)
        {
            //ReplayEventArgs args = new ReplayEventArgs
            //{
            //    EeventType = ReplayEventType.SetReplaySpeed
            //};
            int num = this.cmbSpeed.SelectedIndex - 1;
            if (num < 0)
            {
                num = 0;
            }
            this.cmbSpeed.SelectedIndex = num;
            //args.Param = (this.cmbSpeed.SelectedItem as SpeedInfo).Speed;
            //this.FireReplayEvent(this, args);
            this.UpdateTitle();
        }

        private void btnSpeedUp_Click(object sender, EventArgs e)
        {
            int num;
            //ReplayEventArgs args = new ReplayEventArgs
            //{
            //    EeventType = ReplayEventType.SetReplaySpeed
            //};
            if ((num = this.cmbSpeed.SelectedIndex + 1) >= this.cmbSpeed.Items.Count)
            {
                num = this.cmbSpeed.Items.Count - 1;
            }
            this.cmbSpeed.SelectedIndex = num;
            //args.Param = (this.cmbSpeed.SelectedItem as SpeedInfo).Speed;
            //this.FireReplayEvent(this, args);
            this.UpdateTitle();
        }

        private void chkSkipNoDataSegment_CheckedChanged(object sender, EventArgs e)
        {
            //ReplayEventArgs args = new ReplayEventArgs
            //{
            //    EeventType = ReplayEventType.SkipEmptyTimeSegment,
            //    Param = this.chkSkipNoDataSegment.Checked
            //};
            //this.FireReplayEvent(this, args);
        }

        private void cmbHour_TextChanged(object sender, EventArgs e)
        {
            //if (!Regex.IsMatch(this.cmbHour.Text, "^((([0-1]?[0-9])|([2][0-3]))$)"))
            //{
            //    this.cmbHour.Text = "";
            //}
        }

        private void cmbMinute_TextChanged(object sender, EventArgs e)
        {
            //if (!Regex.IsMatch(this.cmbMinute.Text, "^(([0-5]?[0-9])$)"))
            //{
            //    this.cmbMinute.Text = "";
            //}
        }

        private void cmbSecond_TextChanged(object sender, EventArgs e)
        {
            //if (!Regex.IsMatch(this.cmbSecond.Text, "^(([0-5]?[0-9])$)"))
            //{
            //    this.cmbSecond.Text = "";
            //}
        }

        private void cmbSpeed_SelectedIndexChanged(object sender, EventArgs e)
        {
            //ReplayEventArgs args = new ReplayEventArgs
            //{
            //    EeventType = ReplayEventType.SetReplaySpeed,
            //    Param = (this.cmbSpeed.SelectedItem as SpeedInfo).Speed
            //};
            //this.FireReplayEvent(this, args);
            this.UpdateTitle();
        }

        private void ControlBarDlg_Load(object sender, EventArgs e)
        {
            this.controlSecondPlayTimer = new System.Windows.Forms.Timer();
            this.controlSecondPlayTimer.Interval = 200;
            this.controlSecondPlayTimer.Tick += new EventHandler(this.controlSecondPlayTimer_Tick);
        }

        private void controlSecondPlayTimer_Tick(object sender, EventArgs e)
        {
            if (this.isBtnPreSecondPressed)
            {
                this.btnPreSecond_Click(null, null);
            }
            if (this.isBtnNextSecondPressed)
            {
                this.btnNextSecond_Click(null, null);
            }
        }

        private void curReplayBar_SliderPositionChanged(object setter, TimeSegment timeSeg, DateTime time, bool isDraging)
        {
            if (timeSeg != null)
            {
                //ReplayEventArgs e = new ReplayEventArgs
                //{
                //    EeventType = ReplayEventType.SetPosition,
                //    Param = this.curReplayBar.GetSliderPosition()
                //};
                //this.FireReplayEvent(setter, e);
                DateTime beginTime = time;
                if (beginTime == DateTime.MinValue)
                {
                    beginTime = timeSeg.BeginTime;
                }
                this.lbCurTime.Text = string.Format("{0}", UtilityFunc.GetTimeString(beginTime));
                this.UpdateTitle();
                this.curReplayBar.Invalidate();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        //private void FireReplayEvent(ReplayEventType eventType)
        //{
        //    //ReplayEventArgs e = new ReplayEventArgs
        //    //{
        //    //    EeventType = eventType
        //    //};
        //    //this.FireReplayEvent(this, e);
        //}

        //private void FireReplayEvent(object sender, ReplayEventArgs e)
        //{
        //    if (this.ReplayUIEvent != null)
        //    {
        //        this.ReplayUIEvent(sender, e);
        //    }
        //}

        private DateTime GetAccuratePosTimeFromCtrl()
        {
            string str = this.cmbDate.Text.Trim();
            if (string.IsNullOrEmpty(str))
            {
                return DateTime.MinValue;
            }
            string[] strArray = str.Split(new char[] { '年', '月', '日' });
            int year = UtilityFunc.ToInt(strArray[0], 1);
            int month = UtilityFunc.ToInt(strArray[1], 1);
            int day = UtilityFunc.ToInt(strArray[2], 1);
            int hour = UtilityFunc.ToInt(this.cmbHour.Text.Trim(), 0);
            int minute = UtilityFunc.ToInt(this.cmbMinute.Text.Trim(), 0);
            return new DateTime(year, month, day, hour, minute, UtilityFunc.ToInt(this.cmbSecond.Text.Trim(), 0));
        }

        public void Init()
        {
            int num;
            //Debug.Assert(((CSMReplayApp)CSMApplication.App).DataSupplier != null);
            this.cmbDate.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbSpeed.DropDownStyle = ComboBoxStyle.DropDownList;
            foreach (SpeedInfo info in this.speedTable)
            {
                this.cmbSpeed.Items.Add(info);
            }
            this.cmbSpeed.SelectedIndex = 2;
            for (num = 0; num < 0x18; num++)
            {
                this.cmbHour.Items.Add(num.ToString());
            }
            for (num = 0; num < 60; num++)
            {
                this.cmbMinute.Items.Add(num.ToString());
                this.cmbSecond.Items.Add(num.ToString());
            }
            this.curReplayBar.SliderType = SliderType.Block;
            this.curReplayBar.ForeColor = Color.LightGray;
            this.curReplayBar.IsDrawCacheBar = true;
            this.curReplayBar.SliderPositionChanged += new SliderPostionChangedEventHandler(this.curReplayBar_SliderPositionChanged);
            this.totalDataBar.MaxDisTimeLen = new TimeSpan(0x1f, 0, 0, 0);
            this.totalDataBar.SliderType = SliderType.TimeRange;
            this.totalDataBar.SliderColor = Color.Red;
            this.totalDataBar.SliderPositionChanged += new SliderPostionChangedEventHandler(this.totalDataBar_SliderPositionChanged);
            this.totalDataBar.TipTimeFormat = "yyyy-MM-dd HH:mm";
            this.totalDataBar.IsDrawCacheBar = false;
        }

        private void InitCombDayList()
        {
            this.cmbDate.BeginUpdate();
            this.cmbDate.Items.Clear();
            if (this.totalDataBar.TimeSegmentList != null)
            {
                foreach (DateTime time in this.totalDataBar.TimeSegmentList.GetDayList())
                {
                    this.cmbDate.Items.Add(string.Format("{0}年{1}月{2}日", time.Year, time.Month, time.Day));
                }
                this.cmbDate.EndUpdate();
            }
        }

        private void InitializeComponent()
        {
            TimeSegmentList timeSegmentList1 = new TimeSegmentList();
            TimeSegmentList timeSegmentList2 = new TimeSegmentList();
            TimeSegmentList timeSegmentList3 = new TimeSegmentList();
            TimeSegmentList timeSegmentList4 = new TimeSegmentList();
            this.btnPlay = new System.Windows.Forms.Button();
            this.lbCurReplayBarEndTime = new System.Windows.Forms.Label();
            this.btnSpeedUp = new System.Windows.Forms.Button();
            this.btnSpeedDown = new System.Windows.Forms.Button();
            this.cmbSpeed = new System.Windows.Forms.ComboBox();
            this.btnDisplayKglDialog = new System.Windows.Forms.Button();
            this.btnSave = new System.Windows.Forms.Button();
            this.btnDisplayAnalogDialog = new System.Windows.Forms.Button();
            this.btnReload = new System.Windows.Forms.Button();
            this.lbCurTime = new System.Windows.Forms.Label();
            this.btnModeSwitch = new System.Windows.Forms.Button();
            this.cmbDate = new System.Windows.Forms.ComboBox();
            this.cmbHour = new System.Windows.Forms.ComboBox();
            this.cmbMinute = new System.Windows.Forms.ComboBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.btnAccuratePosition = new System.Windows.Forms.Button();
            this.label10 = new System.Windows.Forms.Label();
            this.label9 = new System.Windows.Forms.Label();
            this.label8 = new System.Windows.Forms.Label();
            this.label7 = new System.Windows.Forms.Label();
            this.cmbSecond = new System.Windows.Forms.ComboBox();
            this.btnReplaySetting = new System.Windows.Forms.Button();
            this.lbCurReplayBarBeginTime = new System.Windows.Forms.Label();
            this.btnNextSecond = new System.Windows.Forms.Button();
            this.btnPreSecond = new System.Windows.Forms.Button();
            this.btnClose = new System.Windows.Forms.Button();
            this.tbTip = new System.Windows.Forms.TextBox();
            this.totalDataBar = new View.Replay.ReplayProgressBar();
            this.curReplayBar = new View.Replay.ReplayProgressBar();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // btnPlay
            // 
            this.btnPlay.Location = new System.Drawing.Point(214, 62);
            this.btnPlay.Name = "btnPlay";
            this.btnPlay.Size = new System.Drawing.Size(75, 23);
            this.btnPlay.TabIndex = 5;
            this.btnPlay.Text = "播放";
            this.btnPlay.UseVisualStyleBackColor = true;
            this.btnPlay.Click += new System.EventHandler(this.btnPlay_Click);
            // 
            // lbCurReplayBarEndTime
            // 
            this.lbCurReplayBarEndTime.AutoSize = true;
            this.lbCurReplayBarEndTime.Location = new System.Drawing.Point(603, 9);
            this.lbCurReplayBarEndTime.Name = "lbCurReplayBarEndTime";
            this.lbCurReplayBarEndTime.Size = new System.Drawing.Size(119, 12);
            this.lbCurReplayBarEndTime.TabIndex = 7;
            this.lbCurReplayBarEndTime.Text = "---------- --:--:--";
            // 
            // btnSpeedUp
            // 
            this.btnSpeedUp.Location = new System.Drawing.Point(151, 62);
            this.btnSpeedUp.Name = "btnSpeedUp";
            this.btnSpeedUp.Size = new System.Drawing.Size(57, 23);
            this.btnSpeedUp.TabIndex = 8;
            this.btnSpeedUp.Text = "加速";
            this.btnSpeedUp.UseVisualStyleBackColor = true;
            this.btnSpeedUp.Click += new System.EventHandler(this.btnSpeedUp_Click);
            // 
            // btnSpeedDown
            // 
            this.btnSpeedDown.Location = new System.Drawing.Point(14, 62);
            this.btnSpeedDown.Name = "btnSpeedDown";
            this.btnSpeedDown.Size = new System.Drawing.Size(54, 23);
            this.btnSpeedDown.TabIndex = 9;
            this.btnSpeedDown.Text = "减速";
            this.btnSpeedDown.UseVisualStyleBackColor = true;
            this.btnSpeedDown.Click += new System.EventHandler(this.btnSpeedDown_Click);
            // 
            // cmbSpeed
            // 
            this.cmbSpeed.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbSpeed.FormattingEnabled = true;
            this.cmbSpeed.Location = new System.Drawing.Point(74, 62);
            this.cmbSpeed.Name = "cmbSpeed";
            this.cmbSpeed.Size = new System.Drawing.Size(72, 20);
            this.cmbSpeed.TabIndex = 10;
            this.cmbSpeed.SelectedIndexChanged += new System.EventHandler(this.cmbSpeed_SelectedIndexChanged);
            // 
            // btnDisplayKglDialog
            // 
            this.btnDisplayKglDialog.Location = new System.Drawing.Point(94, 105);
            this.btnDisplayKglDialog.Name = "btnDisplayKglDialog";
            this.btnDisplayKglDialog.Size = new System.Drawing.Size(75, 23);
            this.btnDisplayKglDialog.TabIndex = 14;
            this.btnDisplayKglDialog.Text = "历史开关量";
            this.btnDisplayKglDialog.UseVisualStyleBackColor = true;
            this.btnDisplayKglDialog.Click += new System.EventHandler(this.btnDisplayKglDialog_Click);
            // 
            // btnSave
            // 
            this.btnSave.Location = new System.Drawing.Point(13, 105);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(75, 23);
            this.btnSave.TabIndex = 13;
            this.btnSave.Text = "存储";
            this.btnSave.UseVisualStyleBackColor = true;
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // btnDisplayAnalogDialog
            // 
            this.btnDisplayAnalogDialog.Location = new System.Drawing.Point(175, 105);
            this.btnDisplayAnalogDialog.Name = "btnDisplayAnalogDialog";
            this.btnDisplayAnalogDialog.Size = new System.Drawing.Size(75, 23);
            this.btnDisplayAnalogDialog.TabIndex = 16;
            this.btnDisplayAnalogDialog.Text = "历史模拟量";
            this.btnDisplayAnalogDialog.UseVisualStyleBackColor = true;
            this.btnDisplayAnalogDialog.Click += new System.EventHandler(this.btnDisplayAnalogDialog_Click);
            // 
            // btnReload
            // 
            this.btnReload.Location = new System.Drawing.Point(256, 105);
            this.btnReload.Name = "btnReload";
            this.btnReload.Size = new System.Drawing.Size(75, 23);
            this.btnReload.TabIndex = 18;
            this.btnReload.Text = "重载";
            this.btnReload.UseVisualStyleBackColor = true;
            this.btnReload.Click += new System.EventHandler(this.btnReload_Click);
            // 
            // lbCurTime
            // 
            this.lbCurTime.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.lbCurTime.Location = new System.Drawing.Point(289, 10);
            this.lbCurTime.Name = "lbCurTime";
            this.lbCurTime.Size = new System.Drawing.Size(168, 14);
            this.lbCurTime.TabIndex = 20;
            this.lbCurTime.Text = "---------- --:--:--";
            // 
            // btnModeSwitch
            // 
            this.btnModeSwitch.Location = new System.Drawing.Point(554, 62);
            this.btnModeSwitch.Name = "btnModeSwitch";
            this.btnModeSwitch.Size = new System.Drawing.Size(75, 23);
            this.btnModeSwitch.TabIndex = 22;
            this.btnModeSwitch.Text = "高级";
            this.btnModeSwitch.UseVisualStyleBackColor = true;
            this.btnModeSwitch.Click += new System.EventHandler(this.btnModeSwitch_Click);
            // 
            // cmbDate
            // 
            this.cmbDate.FormattingEnabled = true;
            this.cmbDate.Location = new System.Drawing.Point(41, 13);
            this.cmbDate.Name = "cmbDate";
            this.cmbDate.Size = new System.Drawing.Size(163, 20);
            this.cmbDate.TabIndex = 24;
            // 
            // cmbHour
            // 
            this.cmbHour.FormattingEnabled = true;
            this.cmbHour.Location = new System.Drawing.Point(41, 40);
            this.cmbHour.Name = "cmbHour";
            this.cmbHour.Size = new System.Drawing.Size(56, 20);
            this.cmbHour.TabIndex = 24;
            this.cmbHour.TextChanged += new System.EventHandler(this.cmbHour_TextChanged);
            // 
            // cmbMinute
            // 
            this.cmbMinute.FormattingEnabled = true;
            this.cmbMinute.Location = new System.Drawing.Point(144, 40);
            this.cmbMinute.Name = "cmbMinute";
            this.cmbMinute.Size = new System.Drawing.Size(56, 20);
            this.cmbMinute.TabIndex = 24;
            this.cmbMinute.TextChanged += new System.EventHandler(this.cmbMinute_TextChanged);
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.btnAccuratePosition);
            this.groupBox1.Controls.Add(this.label10);
            this.groupBox1.Controls.Add(this.label9);
            this.groupBox1.Controls.Add(this.label8);
            this.groupBox1.Controls.Add(this.label7);
            this.groupBox1.Controls.Add(this.cmbSecond);
            this.groupBox1.Controls.Add(this.cmbMinute);
            this.groupBox1.Controls.Add(this.cmbDate);
            this.groupBox1.Controls.Add(this.cmbHour);
            this.groupBox1.Location = new System.Drawing.Point(742, 8);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(217, 100);
            this.groupBox1.TabIndex = 26;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "精确定位";
            // 
            // btnAccuratePosition
            // 
            this.btnAccuratePosition.Location = new System.Drawing.Point(129, 71);
            this.btnAccuratePosition.Name = "btnAccuratePosition";
            this.btnAccuratePosition.Size = new System.Drawing.Size(75, 23);
            this.btnAccuratePosition.TabIndex = 28;
            this.btnAccuratePosition.Text = "确定";
            this.btnAccuratePosition.UseVisualStyleBackColor = true;
            this.btnAccuratePosition.Click += new System.EventHandler(this.btnAccuratePosition_Click);
            // 
            // label10
            // 
            this.label10.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label10.AutoSize = true;
            this.label10.Location = new System.Drawing.Point(21, 71);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(17, 12);
            this.label10.TabIndex = 27;
            this.label10.Text = "秒";
            // 
            // label9
            // 
            this.label9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(110, 45);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(29, 12);
            this.label9.TabIndex = 27;
            this.label9.Text = "分钟";
            // 
            // label8
            // 
            this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(9, 42);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(29, 12);
            this.label8.TabIndex = 27;
            this.label8.Text = "小时";
            // 
            // label7
            // 
            this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(9, 19);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(29, 12);
            this.label7.TabIndex = 27;
            this.label7.Text = "日期";
            // 
            // cmbSecond
            // 
            this.cmbSecond.FormattingEnabled = true;
            this.cmbSecond.Location = new System.Drawing.Point(41, 66);
            this.cmbSecond.Name = "cmbSecond";
            this.cmbSecond.Size = new System.Drawing.Size(56, 20);
            this.cmbSecond.TabIndex = 25;
            this.cmbSecond.TextChanged += new System.EventHandler(this.cmbSecond_TextChanged);
            // 
            // btnReplaySetting
            // 
            this.btnReplaySetting.Location = new System.Drawing.Point(337, 105);
            this.btnReplaySetting.Name = "btnReplaySetting";
            this.btnReplaySetting.Size = new System.Drawing.Size(75, 23);
            this.btnReplaySetting.TabIndex = 27;
            this.btnReplaySetting.Text = "回放设置";
            this.btnReplaySetting.UseVisualStyleBackColor = true;
            this.btnReplaySetting.Click += new System.EventHandler(this.btnReplaySetting_Click);
            // 
            // lbCurReplayBarBeginTime
            // 
            this.lbCurReplayBarBeginTime.AutoSize = true;
            this.lbCurReplayBarBeginTime.Location = new System.Drawing.Point(17, 10);
            this.lbCurReplayBarBeginTime.Name = "lbCurReplayBarBeginTime";
            this.lbCurReplayBarBeginTime.Size = new System.Drawing.Size(119, 12);
            this.lbCurReplayBarBeginTime.TabIndex = 6;
            this.lbCurReplayBarBeginTime.Text = "---------- --:--:--";
            // 
            // btnNextSecond
            // 
            this.btnNextSecond.Location = new System.Drawing.Point(349, 62);
            this.btnNextSecond.Name = "btnNextSecond";
            this.btnNextSecond.Size = new System.Drawing.Size(52, 23);
            this.btnNextSecond.TabIndex = 37;
            this.btnNextSecond.Text = "下一秒";
            this.btnNextSecond.UseVisualStyleBackColor = true;
            this.btnNextSecond.Click += new System.EventHandler(this.btnNextSecond_Click);
            this.btnNextSecond.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnNextSecond_MouseDown);
            this.btnNextSecond.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnNextSecond_MouseUp);
            // 
            // btnPreSecond
            // 
            this.btnPreSecond.Location = new System.Drawing.Point(298, 62);
            this.btnPreSecond.Name = "btnPreSecond";
            this.btnPreSecond.Size = new System.Drawing.Size(52, 23);
            this.btnPreSecond.TabIndex = 36;
            this.btnPreSecond.Text = "上一秒";
            this.btnPreSecond.UseVisualStyleBackColor = true;
            this.btnPreSecond.Click += new System.EventHandler(this.btnPreSecond_Click);
            this.btnPreSecond.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnPreSecond_MouseDown);
            this.btnPreSecond.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnPreSecond_MouseUp);
            // 
            // btnClose
            // 
            this.btnClose.Location = new System.Drawing.Point(647, 62);
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(75, 23);
            this.btnClose.TabIndex = 22;
            this.btnClose.Text = "关闭";
            this.btnClose.UseVisualStyleBackColor = true;
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // tbTip
            // 
            this.tbTip.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.tbTip.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.tbTip.Location = new System.Drawing.Point(0, 169);
            this.tbTip.Name = "tbTip";
            this.tbTip.ReadOnly = true;
            this.tbTip.Size = new System.Drawing.Size(963, 21);
            this.tbTip.TabIndex = 40;
            this.tbTip.Visible = false;
            // 
            // totalDataBar
            // 
            this.totalDataBar.BarBorderColor = System.Drawing.Color.Black;
            this.totalDataBar.BottomBlank = 1;
            this.totalDataBar.CachedDataColor = System.Drawing.Color.DarkGray;
            this.totalDataBar.CachedTimeSegmentList = timeSegmentList1;
            this.totalDataBar.ClickSkipTimeLen = System.TimeSpan.Parse("00:30:00");
            this.totalDataBar.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.totalDataBar.ForeColor = System.Drawing.Color.LightGray;
            this.totalDataBar.IsDrawCacheBar = false;
            this.totalDataBar.LeftBlank = 0;
            this.totalDataBar.Location = new System.Drawing.Point(0, 153);
            this.totalDataBar.MaxDisTimeLen = System.TimeSpan.Parse("05:00:00");
            this.totalDataBar.Name = "totalDataBar";
            this.totalDataBar.RightBlank = 1;
            this.totalDataBar.Size = new System.Drawing.Size(963, 16);
            this.totalDataBar.SliderColor = System.Drawing.Color.DarkGray;
            this.totalDataBar.SliderSize = new System.Drawing.Size(10, 15);
            this.totalDataBar.SliderTimeRangeLen = System.TimeSpan.Parse("00:00:00");
            this.totalDataBar.SliderType = View.Replay.SliderType.Block;
            this.totalDataBar.TabIndex = 41;
            this.totalDataBar.TextColor = System.Drawing.Color.Blue;
            this.totalDataBar.TimeSegmentList = timeSegmentList2;
            this.totalDataBar.TipTimeColor = System.Drawing.Color.Black;
            this.totalDataBar.TipTimeFormat = "HH:mm:ss";
            this.totalDataBar.TopBlank = 0;
            // 
            // curReplayBar
            // 
            this.curReplayBar.BarBorderColor = System.Drawing.Color.Black;
            this.curReplayBar.BottomBlank = 5;
            this.curReplayBar.CachedDataColor = System.Drawing.Color.DarkGray;
            this.curReplayBar.CachedTimeSegmentList = timeSegmentList3;
            this.curReplayBar.ClickSkipTimeLen = System.TimeSpan.Parse("00:30:00");
            this.curReplayBar.ForeColor = System.Drawing.Color.LightGray;
            this.curReplayBar.IsDrawCacheBar = false;
            this.curReplayBar.LeftBlank = 20;
            this.curReplayBar.Location = new System.Drawing.Point(0, 24);
            this.curReplayBar.MaxDisTimeLen = System.TimeSpan.Parse("05:00:00");
            this.curReplayBar.Name = "curReplayBar";
            this.curReplayBar.RightBlank = 20;
            this.curReplayBar.Size = new System.Drawing.Size(740, 28);
            this.curReplayBar.SliderColor = System.Drawing.Color.Gray;
            this.curReplayBar.SliderSize = new System.Drawing.Size(10, 25);
            this.curReplayBar.SliderTimeRangeLen = System.TimeSpan.Parse("00:00:00");
            this.curReplayBar.SliderType = View.Replay.SliderType.Block;
            this.curReplayBar.TabIndex = 29;
            this.curReplayBar.TextColor = System.Drawing.SystemColors.ControlDarkDark;
            this.curReplayBar.TimeSegmentList = timeSegmentList4;
            this.curReplayBar.TipTimeColor = System.Drawing.Color.Black;
            this.curReplayBar.TipTimeFormat = "HH:mm:ss";
            this.curReplayBar.TopBlank = 5;
            // 
            // ControlBarDlg
            // 
            this.ClientSize = new System.Drawing.Size(963, 190);
            this.ControlBox = false;
            this.Controls.Add(this.totalDataBar);
            this.Controls.Add(this.tbTip);
            this.Controls.Add(this.btnNextSecond);
            this.Controls.Add(this.btnPreSecond);
            this.Controls.Add(this.curReplayBar);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.btnClose);
            this.Controls.Add(this.btnModeSwitch);
            this.Controls.Add(this.btnDisplayAnalogDialog);
            this.Controls.Add(this.btnReload);
            this.Controls.Add(this.btnReplaySetting);
            this.Controls.Add(this.lbCurTime);
            this.Controls.Add(this.cmbSpeed);
            this.Controls.Add(this.btnDisplayKglDialog);
            this.Controls.Add(this.btnSave);
            this.Controls.Add(this.lbCurReplayBarEndTime);
            this.Controls.Add(this.lbCurReplayBarBeginTime);
            this.Controls.Add(this.btnSpeedDown);
            this.Controls.Add(this.btnSpeedUp);
            this.Controls.Add(this.btnPlay);
            this.Location = new System.Drawing.Point(50, 600);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "ControlBarDlg";
            this.Text = "回放控制条  1倍速";
            this.Load += new System.EventHandler(this.ControlBarDlg_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        public void InitStage2()
        {
            //Debug.Assert(((CSMReplayApp)CSMApplication.App).DataSupplier != null);
            //this.btnPlay.Enabled = true;
            //CSMReplayApp app = CSMApplication.App as CSMReplayApp;
            //this.totalDataBar.Visible = app.ReplayMode == ReplayMode.HistoryReplay;
            //this.cmbSpeed.SelectedIndex = 2;
            //this.tbTip.Text = app.CmdLineArgument.ReplayTipInfo;
            //this.tbTip.Visible = this.tbTip.Text.Length > 0;
            //this.UpdateTitle();
            this.SetDisplayMode("高级");
        }

        private void SetDisplayMode(string mode)
        {
            //CSMReplayApp app = CSMApplication.App as CSMReplayApp;
            //int num = (this.tbTip.Text.Length > 0) ? 20 : 0;
            //int num2 = (app.ReplayMode == ReplayMode.HistoryReplay) ? 20 : 0;
            int num = 0;
            int num2 = 20;
            if (mode == "精简")
            {
                base.Height = (120 + num) + num2;
                base.Width = 740;
                this.btnModeSwitch.Text = "高级";
            }
            else
            {
                base.Height = (0xa8 + num) + num2;
                base.Width = 0x3ce;
                this.btnModeSwitch.Text = "精简";
            }
            bool flag = mode == "高级";
            this.btnSave.Visible = flag;
            this.btnDisplayAnalogDialog.Visible = flag;
            this.btnDisplayKglDialog.Visible = flag;
            this.btnAccuratePosition.Visible = flag;
            this.btnReload.Visible = flag;
            this.btnReplaySetting.Visible = flag;
        }

        public void SetPositionInTotalTime(object setter, TimeSpan pos)
        {
            this.totalDataBar.SetSliderPosition(setter, pos);
        }

        public void SetReplayInfo(string infoType, object info)
        {
            string str = infoType;
            if ((str != null) && (str == "ReplayRecCount"))
            {
                int num = (int)info;
                this.lastReplayRecCount = num;
            }
        }

        //public void SetReplayParam(ReplaySettingParam param)
        //{
        //    this.curReplayBar.ForeColor = param.UnBufferedDataColor;
        //    this.curReplayBar.CachedDataColor = param.BufferedDataColor;
        //    this.curReplayBar.SliderColor = param.SliderColor;
        //    this.curReplayBar.Invalidate();
        //    this.totalDataBar.ForeColor = param.UnBufferedDataColor;
        //    this.totalDataBar.SliderColor = param.SliderColor;
        //    this.totalDataBar.Invalidate();
        //    this.chkSkipNoDataSegment.Checked = param.IsSkipEmptyDataSegment;
        //    //CSMReplayApp app = CSMApplication.App as CSMReplayApp;
        //    //this.btnReload.Enabled = app.ReplayMode == ReplayMode.HistoryReplay;
        //}

        public void SetTimePostion(object setter, TimeSpan pos)
        {
            this.curReplayBar.SetSliderPosition(setter, pos);
        }

        public void Stop()
        {
            this.btnPlay_Click(null, null);
        }

        private void totalDataBar_SliderPositionChanged(object setter, TimeSegment timeSeg, DateTime time, bool isDraging)
        {
            TimeSegmentList list2 = this.totalDataBar.TimeSegmentList.ClipSegment(timeSeg, time, this.curReplayBar.MaxDisTimeLen);
            this.curReplayBar.TimeSegmentList = list2;
            this.curReplayBar.SetSliderPosition(setter, new TimeSpan(0L));
            this.curReplayBar.CachedTimeSegmentList.SegmentList.Clear();
            //ReplayEventArgs e = new ReplayEventArgs
            //{
            //    EeventType = ReplayEventType.SetReplayRange,
            //    Param = list2
            //};
            //this.FireReplayEvent(setter, e);
            this.UpdateTimeSelCtrl(this.curReplayBar.TimeSegmentList.GetBeginTime());
            this.UpdateDisTime();
            this.curReplayBar.Invalidate();
        }

        private void UpdateDisTime()
        {
            TimeSegmentList timeSegmentList = this.curReplayBar.TimeSegmentList;
            DateTime endTime = timeSegmentList.GetEndTime();
            DateTime beginTime = timeSegmentList.GetBeginTime();
            if (timeSegmentList.GetTotalTimeLen() < this.curReplayBar.MaxDisTimeLen)
            {
                endTime = beginTime + this.curReplayBar.MaxDisTimeLen;
            }
            this.lbCurReplayBarBeginTime.Text = UtilityFunc.GetTimeString(beginTime);
            this.lbCurReplayBarEndTime.Text = UtilityFunc.GetTimeString(endTime);
            this.lbCurTime.Text = UtilityFunc.GetTimeString(this.curReplayBar.GetSliderDateTime());
        }

        private void UpdateTimeSelCtrl(DateTime time)
        {
            this.cmbDate.Text = string.Format("{0}年{1}月{2}日", time.Year, time.Month, time.Day);
            this.cmbHour.Text = time.Hour.ToString();
            this.cmbMinute.Text = time.Minute.ToString();
            this.cmbSecond.Text = time.Second.ToString();
        }

        private void UpdateTitle()
        {
            //string str = ("当前版本：" + Assembly.GetExecutingAssembly().GetName().Version.ToString()) + " (" + Util.GetPe32Time() + ")";
            //CSMReplayApp app = CSMApplication.App as CSMReplayApp;
            //if (!string.IsNullOrEmpty(app.CmdLineArgument.ReplayBarTitle))
            //{
            //    this.Text = string.Format("{0} {1}   {2}", app.CmdLineArgument.ReplayBarTitle, this.cmbSpeed.Text, str);
            //}
            //else if (app.ReplayMode == ReplayMode.HistoryReplay)
            //{
            //    this.Text = string.Format("历史回放  {0}   {1}", this.cmbSpeed.Text, str);
            //}
            //else
            //{
            //    this.Text = string.Format("再现回放  {0}   {1}", this.cmbSpeed.Text, str);
            //}
        }

        // Properties
        public TimeSegmentList CacheTimeList
        {
            get
            {
                return this.curReplayBar.CachedTimeSegmentList;
            }
            set
            {
                this.curReplayBar.CachedTimeSegmentList = value;
                this.curReplayBar.Invalidate();
            }
        }

        public TimeSegmentList CurReplayTimeList
        {
            get
            {
                return this.curReplayBar.TimeSegmentList;
            }
        }

        public TimeSpan DisMaxTimeLen
        {
            get
            {
                return this.curReplayBar.MaxDisTimeLen;
            }
            set
            {
                this.curReplayBar.MaxDisTimeLen = value;
                this.totalDataBar.SliderTimeRangeLen = this.curReplayBar.MaxDisTimeLen;
            }
        }

        public TimeSegmentList TotalTimeList
        {
            get
            {
                return this.totalDataBar.TimeSegmentList;
            }
            set
            {
                this.totalDataBar.TimeSegmentList = value;
                if (value != null)
                {
                    this.totalDataBar.MaxDisTimeLen = value.GetTotalTimeLen();
                }
                else
                {
                    this.totalDataBar.MaxDisTimeLen = new TimeSpan();
                }
                this.InitCombDayList();
            }
        }

        // Nested Types
        private class SpeedInfo
        {
            // Methods
            public SpeedInfo(float speed, string text)
            {
                this.Speed = speed;
                this.Text = text;
            }

            public override string ToString()
            {
                return this.Text;
            }

            // Properties
            public float Speed { get; set; }

            public string Text { get; set; }
        }

        private void button11_Click(object sender, EventArgs e)
        {

        }
    }
}
